package com.xiaoxi.bms.domain.user;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;

/**
 * @Author xiaoxi
 * @ProjectName springcloudbms
 * @PackageName domain
 * @ClassName BMSUser
 * @Description TODO
 * @Date 2023/2/2 9:09
 * @Version 1.0
 */
@TableName("bms_user")
@Data
public class BMSUser implements UserDetails, Serializable {

    /**
     *  序号
     */
    @TableId(type = IdType.AUTO)
    private Long id;

    /**
     *  用户名
     */
    private String username;            // 唯一

    /**
     *  密码
     */
    private String password;

    /**
     * 乐观锁
     */
    @TableField(fill = FieldFill.INSERT)
    private Long version;

    /**
     *  创建人
     */
    @TableField(fill = FieldFill.INSERT)
    private Long createId;

    /**
     *  创建时间
     */
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    /**
     *  修改人
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Long modifyId;

    /**
     *  修改时间
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime modifyTime;

    /**
     *  用户锁定：true 锁定 , false 未锁定     用于：登陆N次，锁定
     */
    private boolean accountNonLocked;

    /**
     *  启用：true 启用 , false 停用
     */
    private boolean enabled;

    /**
     *  账户过期：true 过期 , false 未过期     暂时不需要
     */
    private boolean accountNonExpired;

    /**
     *  账户凭证：true 过期 , false 未过期     暂时不需要
     */
    private boolean credentialsNonExpired;

    /**
     * 假删除 true 删除  false 未删除
     */
    private Boolean del;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        Collection<GrantedAuthority> authorities = new ArrayList<>();
        SimpleGrantedAuthority authority = new SimpleGrantedAuthority("admin");
        authorities.add(authority);
        return authorities;
    }
}
